package com.dengdai.applibrary.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dengdai.applibrary.annotation.InjectUtils;
import com.dengdai.applibrary.config.BaseViewInfo;
import com.dengdai.applibrary.utils.LogUtils;
import com.dengdai.applibrary.utils.Operation;

/**
 * @说明 Fragment的基类
 * @作者 LY
 * @时间 15/12/21 16:17
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public abstract class BaseFragment extends Fragment implements IBaseFragment {
    public String TAG = this.getClass().getSimpleName();
    /**
     * 动画类型
     **/
    private int mAnimationType = NONE;
    private static Operation mOperation = null;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mOperation = new Operation(getActivity());
        business(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutResID(), container, false);
        InjectUtils.initInjectedView(this, view);
        LogUtils.v(TAG, "onCreateView");
        initView(view);
        return view;
    }

    /**
     * 界面消失操作
     */
    public void finish() {
        switch (mAnimationType) {
            case IBaseActivity.LEFT_RIGHT:
                getActivity().overridePendingTransition(0, BaseView.gainResId(getActivity(), BaseView.ANIM, BaseViewInfo.SLIDE_RIGHT_OUT));
                break;
            case IBaseActivity.TOP_BOTTOM:
                getActivity().overridePendingTransition(0, BaseView.gainResId(getActivity(), BaseView.ANIM, BaseViewInfo.PUSH_UP_OUT));
                break;
            case IBaseActivity.FADE_IN_OUT:
                getActivity().overridePendingTransition(0, BaseView.gainResId(getActivity(), BaseView.ANIM, BaseViewInfo.FADE_OUT));
                break;
        }
        mAnimationType = NONE;
    }

    /**
     * 获取共通操作
     *
     * @return 初始化的共同操作
     */
    public static Operation getOperation() {
        return mOperation;
    }

    public void startProgressDialog() {
    }

    public void stopProgressDialog() {
    }
}
